package com.eh.taxation.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eh.commonutils.R;
import com.eh.taxation.entity.Admin;
import com.eh.taxation.service.AdminService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/taxation/user")
@Api(value = "TaxLoginController", tags = "管理员登录")
public class TaxLoginController {

    @Autowired
    private AdminService adminService;

    @PostMapping("login")
    public R login(@RequestBody Admin admin) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("username", admin.getUsername());
        int count = adminService.count(wrapper);
        if (count > 0) {
            wrapper.eq("password", admin.getPassword());
            Admin user = adminService.getOne(wrapper);
            if (user != null) {
                return R.ok().data("token", user.getId());
            } else {
                return R.error().message("密码错误");
            }
        }
        return R.error().message("登陆失败");
    }
    // info
    @GetMapping("info")
    public R info() {
        return R.ok().data("roles", "[admin]").data("name", "admin").data("avatar", "http://erhuoweirdo-edu.oss-cn-beijing.aliyuncs.com/2021/01/23/ef2e365e-4ce0-4c42-ba59-d1c5bd99769cu=3887693975,4189960740&fm=26&gp=0.jpg");
    }

}
